<?php

    /**
    * Save Login Information - for login page
    * for project Kurtulus Law and Credit
    * 
    * @author trungdt
    * @since Aug 29
    * @copyright Absoft Viet Nam
    */
    if (!defined('EXPONENT')) exit('');

    $backup_loc = $loc->src;

    if (!isset($_POST['logininfo_id'])) 
        $_POST['logininfo_id']=-1;

    $logininfo = $db->selectObject('textitem','id='.intval($_POST['logininfo_id']));
    if ($logininfo) {
        $loc = unserialize($logininfo->location_data);
    }
    else
    {
        $loc=null;
        $loc->mod="textmodule";
        $loc->src=$backup_loc;
        $loc->int="";
    }

    $logininfo->location_data = serialize($loc);
    $logininfo->text=$_REQUEST['logininfo'];
    $logininfo->approved = 1;

    if (exponent_permissions_check('edit',$loc)) {
        if (isset($logininfo->id)) {
            $db->updateObject($logininfo,'textitem');
        } else {
            $db->insertObject($logininfo,'textitem');
        }
    }

    // head info
    if (!isset($_POST['head_id'])) 
        $_POST['head_id'] = -1;

    $head = $db->selectObject('textitem','id='.intval($_POST['head_id']));
    if ($head) {
        $loc = unserialize($head->location_data);
    }
    else
    {
        $loc=null;
        $loc->mod="textmodule";
        $loc->src=$backup_loc."_head";
        $loc->int="";
    }

    $head->location_data = serialize($loc);
    $head->text=$_REQUEST['login_head'];
    $head->approved = 1;

    if (exponent_permissions_check('edit',$loc)) {
        if (isset($head->id)) {
            $db->updateObject($head,'textitem');
        } else {
            $db->insertObject($head,'textitem');
        }
    }
    
    //
    if (!isset($_POST['mobile_id'])) 
        $_POST['mobile_id'] = -1;

    $mobile = $db->selectObject('textitem','id='.intval($_POST['mobile_id']));
    if ($mobile) {
        $loc = unserialize($mobile->location_data);
    }
    else
    {
        $loc=null;
        $loc->mod="textmodule";
        $loc->src=$backup_loc."_mobile";
        $loc->int="";
    }

    $mobile->location_data = serialize($loc);
    $mobile->text=$_REQUEST['login_mobile'];
    $mobile->approved = 1;

    if (exponent_permissions_check('edit',$loc)) {
        if (isset($mobile->id)) {
            $db->updateObject($mobile,'textitem');
        } else {
            $db->insertObject($mobile,'textitem');
        }
    }
    
    // clear text cache
    exponent_sessions_setCacheValue('textmodule',null);

    exponent_flow_redirect();
?>